// index.ts
// 获取应用实例
const app = getApp<IAppOption>()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Component({
  data: {
    logoUrl: 'https://c-ssl.dtstatic.com/uploads/blog/202207/13/20220713222221_4509f.thumb.400_0.jpeg',
    bossNickname: 'Potato',
    tagline: '守护全世界最好的土豆子',
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '微信用户',
    },
    clickLogin: false,
    nicknameFocus: false,
    hasAvatar: false,
    hasNickname: false,
    isLoggingIn: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
  },
  methods: {
    onAutoLogin() {
      this.setData({
        clickLogin: true,
      })
    },
    onChooseAvatar(e: any) {
      const { avatarUrl } = e.detail
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasAvatar: true,
      })
    },
    inputBlur() {
    },
    expInput: function () {
    },
    inputChange: function (e: any) {
      this.setData({
        'userInfo.nickname': e.detail.value,
        hasNickname: true,
        isLoggingIn: true,
      })
      setTimeout(() => {
        wx.switchTab({
          url: '/pages/index/index',
        })
      }, 1000)
    },

    nicknameClick() {
      this.setData({
        nicknameFocus: true,
      })
    },
    getUserProfile() {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
  },
})
